package com.ytjj.qmyx.admin.controller;

import com.ytjj.common.api.CommonResult;
import com.ytjj.qmyx.admin.annotation.OperLog;
import com.ytjj.qmyx.admin.constants.SysLogConstants;
import com.ytjj.qmyx.admin.service.DynamicMatchingService;
import com.ytjj.qmyx.mall.model.DynamicMatching;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 *动态推荐信息管理
 */
@RestController
@RequestMapping("/dynamicMatching")
public class DynamicMatchingController {

    @Autowired
    private DynamicMatchingService dynamicMatchingService;

    /**
     * 根据动态id获取动态推荐信息
     * @param dynamicId
     * @return
     */
    @GetMapping(value = "/getDynamicMatching")
    public CommonResult getDynamicMatching(@RequestParam Integer dynamicId) {
        DynamicMatching dynamicMatching = dynamicMatchingService.getDynamicMatching(dynamicId);
        return CommonResult.success(dynamicMatching);
    }

    /**
     * 修改/增加动态推荐信息
     * @param dynamicMatching
     * @return
     */
    @PostMapping("/updateDynamicMatching")
    @OperLog(operModule = "动态推荐模块", operDesc = "修改动态推荐信息", operType = SysLogConstants.OPERATION_UPDATE)
    public CommonResult updateDynamicMatching(@RequestBody DynamicMatching dynamicMatching) {
        int count = dynamicMatchingService.doDynamicMatching(dynamicMatching);
        if (count > 0) {
            return CommonResult.success(count);
        } else {
            return CommonResult.failed();
        }
    }

}
